package com.hz.web.service.impl;


import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Service;
import com.hz.web.dao.TpDao;
import com.hz.web.entity.TpEntity;
import com.hz.web.service.ItpService;
import com.hz.web.util.Uid;
@Service
public class TpImpl implements ItpService {

	@Resource
	private TpDao tpDao;
	/**
	 * 添加民意调查数据
	 * @param entity
	 * @return
	 */
	@Override
	public int addTp(HttpServletRequest request,TpEntity entity) {
		int row = -1;
		try {
			if(entity!=null){
				entity.setTpId("tpid"+Uid.getUid());//主键
				String ipAddress=getRemortIP(request);
				entity.setIpAddress(ipAddress);
				row = tpDao.addTp(entity);
			}
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		return row;
	}

	//获取Ip地址
	public String getRemortIP(HttpServletRequest request) {
		  if (request.getHeader("x-forwarded-for") == null) {
		   return request.getRemoteAddr();
		  }
		  return request.getHeader("x-forwarded-for");
		 }

	/**
	 * 根据不同类型查询条数 
	 * @param parmsMap
	 * @return
	 */
	@Override
	public int queryCountByTypeId(Map<String, Object> parmsMap) {
		int count=-1;
		try {
			count = tpDao.queryCountByTypeId(parmsMap);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return count;
	} 
}
